package com.xinzhi.utils;

import com.github.pagehelper.PageInfo;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * Description 分页的公共实体类
 * Author yangjin
 * Date 2021/12/5 21:59
 * Version 1.0
 */
@Data
@NoArgsConstructor
public class Page<T> {

    private int pageNum;

    private int pageSize;

    private long pages;

    private long total;

    private List<T> list;

    public Page<T> toPage(PageInfo<T> pageInfo, Page<T> page){
        page.setPageNum(pageInfo.getPageNum());
        page.setPageSize(pageInfo.getPageSize());
        page.setList(pageInfo.getList());
        page.setPages(pageInfo.getTotal() % pageInfo.getPageSize() == 0 ? pageInfo.getTotal()/pageInfo.getPageSize():(pageInfo.getTotal()/pageInfo.getPageSize())+1);
        page.setTotal(pageInfo.getTotal());
        return page;
    }

    public Page(int pageNum, int pageSize, long total, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        this.pages = total % pageSize == 0 ? total/pageSize:(total/pageSize)+1;
    }
}
